[mirrors]
http://serf.googlecode.com/files/serf-1.3.2.tar.bz2

[vars]
filesize=139861
sha512=4e9a117c08db172cfc159d43b7a1a5cd4d888e74cbc8b55af6c5e5dc70562d4a3e1d875093fa40c515c2e8e3e290f91238491ec260d7c67b6613b83ede47543e

[deps]
apr
apr-util
libressl
zlib

[deps.host]
scons

[build]
patch -p1 < "$K"/serf-format-UB.patch
cat << EOF > apr-1-config
#!/bin/sh
res=\$($butch_root_dir$butch_prefix/bin/apr-1-config "\$@")
rc=\$?
printf "%s\n" "\$res" | sed \
  -e 's,-I'$butch_prefix'/include,-I'"$butch_root_dir""$butch_prefix"/include',' \
  -e 's,-L'$butch_prefix'/lib,-L'"$butch_root_dir""$butch_prefix"/lib',' \
  -e 's,-I/usr/include,,g'
exit \$rc
EOF
chmod +x apr-1-config
getfullpath() {
	type "$1" | awk '{print $NF}'
}
replace_cc_arg1() {
	echo $CC | awk -v a=$(getfullpath $CC) \
	           '{for(i=2;i<=NF;i++) a = a " " $i; print a}'
}
# serfs scons script doesnt like empty prefix.
[ -z "$butch_prefix" ] && butch_prefix=/
sed -i 's,usr,loosr,' SConstruct
scons CC="$(replace_cc_arg1)" CFLAGS="-D_GNU_SOURCE $optcflags" LINKFLAGS="$optldflags" \
  PREFIX="$butch_prefix" APR=$PWD/apr-1-config APU=$PWD/apr-1-config \
  ZLIB="$butch_root_dir""$butch_prefix" \
  OPENSSL="$butch_root_dir""$butch_prefix" \
  -j$MAKE_THREADS

mkdir -p "$butch_install_dir""$butch_prefix"

scons install --install-sandbox="$butch_install_dir"
